package result

type ResultCode struct {
	Code int    `json:"code"`
	Msg  string `json:"message"`
}

func generateErrorResultFunc(code int) func(msg string) []byte {
	return func(msg string) []byte {
		result := &ResultCode{
			Code: code,
			Msg:  msg,
		}
		return Error(result)
	}
}

func newResultCode(code int, msg string) *ResultCode {
	return &ResultCode{
		Code: code,
		Msg:  msg,
	}
}

var (
	SUCCESS           = newResultCode(20000, "success")
	SEQUEENCE_ERROR   = newResultCode(5000, "json marshal error")
	PARAM_PARSE_ERROR = newResultCode(5100, "param parse error")
	PARAM_EMPTY_ERROR = newResultCode(5101, "empty param is not allowed !")

	AGENT_REGISTER_ERROR                    = newResultCode(5300, "agent register error")
	AGENT_CREATE_CONTAINER_ERROR            = newResultCode(5301, "agent create container error")
	AGENT_START_CONTAINER_ERROR             = newResultCode(5302, "agent start container error")
	AGENT_INSPECT_CONTAINER_ERROR           = newResultCode(5303, "agent inspect container error")
	AGENT_HAS_CONTAINER_ERROR               = newResultCode(5304, "agent has container error")
	AGENT_RELEASE_CONTAINER_ERROR           = newResultCode(5305, "agent release container error")
	AGENT_LIST_CONTAINERS_ERROR             = newResultCode(5305, "agent list container error")
	AGENT_HEALTH_CHECK_CONTAINER_ERROR      = newResultCode(5306, "agent health check container error")
	AGENT_GPU_RESOURCES_NOT_AVAILABLE_ERROR = newResultCode(5307, "agent gpu manager not available error")
	AGENT_IMAGE_NOT_FOUND_ERROR             = newResultCode(5308, "agent local image not found error")

	AGENT_PULL_IMAGE_ERROR = newResultCode(5400, "agent pull images error")
	PERSIST_INFO_ERROR     = newResultCode(5500, "persist information to database error")
	HOST_PORT_IS_USED      = newResultCode(5600, "the host port is already used")
)

const (
	ControllerParamParseError = 10000 + iota
	CreateInstanceParamParseError
	CrtIstRowImage
	ListInstanceParamParseError
	ReleaseInstanceParamParseError
)

var (
	ParseCreateInstanceRowImageError = generateErrorResultFunc(CrtIstRowImage)
)
